﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BDCS.Model;
using BDCS.BLL;

namespace BDCS.UI
{
    public partial class SelectMainWindow : Form
    {
        #region 成员字段
        private BDCS.BLL.T_BuildTyppes bllBuildType;
        private BDCS.BLL.T_SubBuildTyppes bllSubBuildType;
        private BDCS.BLL.T_BuildDesignDcriterionTypes bllBuildDesignDcriterionType;
        private BDCS.BLL.T_BuildDesignDcriterionSubTypes bllBuildDesignDcriterionSubType;
        private int btid;
        private int sbtid;
        private int dtid;
        private int dstid;
        #endregion
        public SelectMainWindow()
        {
            InitializeComponent();
        }
        private void SelectMainWindow_Load(object sender, EventArgs e)
        {
            CmbBuildTypeDataBinding();
            CmbSubBuildTypeDataBinding(btid);
            CmbBuildDesignDcriterionTypeDataBinding();
           // CmbSubDcriterionDataBinding(dtid);
        }
        private void CmbBuildTypeDataBinding()
        {
            DataSet dataSet = new DataSet();
            bllBuildType = new BLL.T_BuildTyppes();
            dataSet = bllBuildType.GetAllList();
            cmbBuildType.DataSource = dataSet.Tables[0];
            cmbBuildType.DisplayMember = dataSet.Tables[0].Columns["BTName"].ToString();
            cmbBuildType.ValueMember = dataSet.Tables[0].Columns["BTID"].ToString();

        }
        private void CmbSubBuildTypeDataBinding(int btid)
        {
            DataSet dataSet = new DataSet();
            bllSubBuildType = new BLL.T_SubBuildTyppes();
            //   cmbSubBuildType.DataSource = null;
            dataSet = bllSubBuildType.GetList("BTID=" + "'" + btid + "'");
            if (dataSet.Tables[0].Rows.Count != 0)
            {
                cmbSubBuildType.DataSource = dataSet.Tables[0];
                cmbSubBuildType.DisplayMember = dataSet.Tables[0].Columns["SBTName"].ToString();
                cmbSubBuildType.ValueMember = dataSet.Tables[0].Columns["SBTID"].ToString();
            }
            else
            {
                cmbSubBuildType.DataSource = null;
            }
        }
        private void CmbBuildDesignDcriterionTypeDataBinding()
        {
            DataSet dataSet = new DataSet();
            bllBuildDesignDcriterionType = new BLL.T_BuildDesignDcriterionTypes();
            dataSet = bllBuildDesignDcriterionType.GetAllList();
            cmbDcriterionType.DataSource = dataSet.Tables[0];
            cmbDcriterionType.DisplayMember = dataSet.Tables[0].Columns["DTName"].ToString();
            cmbDcriterionType.ValueMember = dataSet.Tables[0].Columns["DTID"].ToString();
        }
        //private void CmbSubDcriterionDataBinding(int dtid)
        //{
        //    DataSet dataSet = new DataSet();
        //    bllBuildDesignDcriterionSubType = new BLL.T_BuildDesignDcriterionSubTypes();
        //    dataSet = bllBuildDesignDcriterionSubType.GetList("DTID=" + "'" + dtid + "'");
        //    cmbSubDcriterion.DataSource = dataSet.Tables[0];
        //    cmbSubDcriterion.DisplayMember = dataSet.Tables[0].Columns["DSTName"].ToString();
        //    cmbSubDcriterion.ValueMember = dataSet.Tables[0].Columns["DSTID"].ToString();
        //}
        private void cmbBuildType_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                btid = Convert.ToInt32(cmbBuildType.SelectedValue);
                CmbSubBuildTypeDataBinding(btid);
            }
            catch (Exception ex)
            {
                DataRowView drv = (DataRowView)cmbBuildType.SelectedValue;
                btid = Convert.ToInt32(drv.Row["BTID"]);
            }
        }

        private void cmbSubBuildType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbSubBuildType.DataSource != null)
            {
                try
                {

                    sbtid = Convert.ToInt32(cmbSubBuildType.SelectedValue);
                    this.btnDefineSelect.Enabled = true;
                }
                catch (Exception ex)
                {
                    DataRowView drv = (DataRowView)cmbSubBuildType.SelectedValue;
                    sbtid = Convert.ToInt32(drv.Row["SBTID"]);
                    this.btnDefineSelect.Enabled = true;
                }
            }
            else
            {
                this.btnDefineSelect.Enabled = false;
                MessageBox.Show("所选建筑大类无下属子类，请重新选择！");
            }
        }

        private void cmbDcriterionType_SelectedIndexChanged(object sender, EventArgs e)
        {

            try
            {
                dtid = Convert.ToInt32(cmbDcriterionType.SelectedValue);
              //  CmbSubDcriterionDataBinding(dtid);
            }
            catch (Exception ex)
            {
                DataRowView drv = (DataRowView)cmbDcriterionType.SelectedValue;
                dtid = Convert.ToInt32(drv.Row["DTID"]);
            }
        }


        private void btnDefineSelect_Click(object sender, EventArgs e)
        {
            AddDefineSelect ADS = new AddDefineSelect(btid, sbtid, dtid, dstid);
            ADS.Show();
        }
        //private void cmbSubDcriterion_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        dstid = Convert.ToInt32(cmbSubDcriterion.SelectedValue);
        //    }
        //    catch (Exception ex)
        //    {
        //        DataRowView drv = (DataRowView)cmbSubDcriterion.SelectedValue;
        //        dstid = Convert.ToInt32(drv.Row["DSTID"]);
        //    }
        //}

        private void 编辑EToolStripMenuItem_Click(object sender, EventArgs e)
        {
            UI.SystemManageWindow s = new SystemManageWindow();
            s.Show();
        }
    }
}
